package com.landeb.shop.huo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.landeb.shop.R;
import com.landeb.shop.huo.bean.BeanActAddressSelect;

import java.util.List;

/**
 * Created by blade on 2016/11/29.
 */

public class ActAddressSelectLVAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<BeanActAddressSelect.DataBean> mList;

    public ActAddressSelectLVAdapter(Context context, List<BeanActAddressSelect.DataBean> list) {
        mContext = context;
        mList = list;
        mInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_act_address_select_lv, parent, false);

            holder = new ViewHolder();

            holder.mName = (TextView) convertView.findViewById(R.id.item_act_address_select_tv_name);
            holder.mPhoneNum = (TextView) convertView.findViewById(R.id.item_act_address_select_tv_phoneNum);
            holder.mAddress = (TextView) convertView.findViewById(R.id.item_act_address_select_tv_address);
            holder.mDefaultIcon = (TextView) convertView.findViewById(R.id.item_act_address_select_tv_icon);
            holder.llEdit = (LinearLayout) convertView.findViewById(R.id.item_act_address_select_ll_edit);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        holder.mName.setText(mList.get(position).getRealname());
        holder.mPhoneNum.setText(mList.get(position).getMobile());

        holder.mAddress.setText(mList.get(position).getProvince() + mList.get(position).getCity()
                + mList.get(position).getCountry() + mList.get(position).getTown()
                + mList.get(position).getAddress());

        holder.llEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO: 2016/11/29 编辑事件
                String ID = mList.get(position).getId();
            }
        });

        if (mList.get(position).getIs_default().equals("1")) {
            holder.mDefaultIcon.setVisibility(View.VISIBLE);

        } else {
            holder.mDefaultIcon.setVisibility(View.GONE);
        }


        return convertView;
    }

    private class ViewHolder {
        private TextView mName; //文字
        private TextView mPhoneNum;
        private TextView mAddress;
        private TextView mDefaultIcon;
        private LinearLayout llEdit;
    }
}
